﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using TaxData.Tax;

namespace TaxBiz.Tax
{
    /// <summary>
    /// 税收预警逻辑层
    /// </summary>
    public class AlarmBiz
    {
        /// <summary>
        /// 计算应税
        /// </summary>
        /// <param name="year">年份</param>
        /// <param name="message">返回信息</param>
        /// <returns>是否成功</returns>
        public static bool ComputeTax(int year, ref string message)
        {
            bool isSucc = AlarmData.ComputeTax(year, ref message);
            return isSucc;
        }

        /// <summary>
        /// 获取预警列表
        /// </summary>
        public static DataTable GetList(string strWhere, int pageSize, int page, ref int allCount)
        {
            DataTable dt = AlarmData.GetList(strWhere, pageSize, page, ref allCount);
            if (dt != null)
            {
                dt.Columns.Add("RequireTax");
                dt.Columns.Add("CompleteTax");
                dt.Columns.Add("BujiaoTax");
                TaxBiz.SysConfig.TaxsBiz tb = new SysConfig.TaxsBiz();
                foreach (DataRow dr in dt.Rows)
                {
                    Dictionary<string, decimal> requireTaxDic = new Dictionary<string, decimal>();
                    Dictionary<string, decimal> completeTaxDic = new Dictionary<string, decimal>();
                    tb.GetTaxDescDic(dr, out requireTaxDic, out completeTaxDic);

                    foreach (KeyValuePair<string, decimal> pair in requireTaxDic)
                    {
                        dr["RequireTax"] += pair.Key + ":" + pair.Value.ToString() + "<br/>";
                    }
                    foreach (KeyValuePair<string, decimal> pair in completeTaxDic)
                    {
                        dr["CompleteTax"] += pair.Key + ":" + pair.Value.ToString() + "<br/>";
                    }
                    if (dr["bTotalTax"] == null || dr["bTotalTax"] == DBNull.Value)
                    {
                        dr["bTotalTax"] = 0;
                    }
                    //dr["BujiaoTax"] = bujiaoTax;
                }
            }
            return dt;
        }
    }
}
